<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">

            <h:form id="cidadaoForm" enctype="multipart/form-data">
                <br/>
                <h3 class="title">Cadastrar Proprietário</h3>
                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <p:panel id="personPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix both ">
                    <h4 class="title">Dados Gerais</h4>

                    <p:outputLabel id="personOutputLabel" value="Pessoa: " styleClass="grid_3" style="top: 6px" />
                    <div class="grid_8">
                        <p:selectOneRadio id="personRadioButton" value="#{managerProprietario.proprietario.tipoDocumento}" >
                            <f:selectItems value="#{managerProprietario.tipoDocumentoList()}" />
                            <p:ajax event="change" update=":cidadaoForm:personPanel" />
                        </p:selectOneRadio>
                    </div>

                    <div class="clear-both"/>

                    <p:outputLabel id="tipoDocumentoLabel" for="tipoDocumentoInput"
                                   value="#{managerProprietario.proprietario.tipoDocumento}: " 
                                   styleClass="grid_3"/>

                    <p:inputMask id="tipoDocumentoInput" 
                                 value="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                          managerProprietario.proprietario.cpf : managerProprietario.proprietario.cnpj}"
                                 mask="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                         '999.999.999-99':'99.999.999/9999-99'}"
                                 styleClass="grid_8" > 
                    </p:inputMask>
                    <div class="clear-both" />

                    <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeInputText" 
                                   rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}"/>
                    <p:inputText id="nomeInputText" styleClass="grid_20 ajustInput"
                                 value="#{managerProprietario.proprietario.nome}" 
                                 rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />

                    <p:outputLabel value="RG: " styleClass="grid_3" for="rgInputText" 
                                   rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />
                    <p:inputText id="rgInputText" styleClass="grid_8" value="#{managerProprietario.proprietario.rg}" 
                                 rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />

                    <p:outputLabel value="Org. Emissor: " styleClass="grid_3" for="orgInputText" 
                                   rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />
                    <p:inputText id="orgInputText" styleClass="grid_8" value="#{managerProprietario.proprietario.orgaoEmissor}" 
                                 rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />
                    
                    <p:outputLabel value="Profissão: " styleClass="grid_3" for="profissaoInputText" 
                                   rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />
                    <p:inputText id="profissaoInputText" styleClass="grid_8" value="#{managerProprietario.proprietario.profissao}" 
                                 rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />

                    <p:outputLabel value="Local de Trabalho:" styleClass="grid_3 localTrabalhoLabel" for="localTrabalhoInputText" 
                                   rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />
                    <p:inputText id="localTrabalhoInputText" styleClass="grid_8" value="#{managerProprietario.proprietario.localTrabalho}" 
                                 rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />
                    <div class="clear"/> 
                    <p:outputLabel value="Data Nasc.: " styleClass="grid_3" for="dateNascCalendar" 
                                   rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />
                    <p:calendar id="dateNascCalendar" value="#{managerProprietario.proprietario.dataNasc}" showOn="both" 
                                locale="pt" yearRange="1900:2020" navigator="true" pattern="dd/MM/yyyy"
                                styleClass="grid_8" rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CPF'}" />

                    <div class="clear"/> 
                    <p:outputLabel value="Nome Fantasia: " styleClass="grid_3 companyLabel"
                                   for="nameFantasyInputText" rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />
                    <p:inputText id="nameFantasyInputText" styleClass="grid_20 ajustInput"
                                 value="#{managerProprietario.proprietario.nomeFantasia}" 
                                 rendered="#{managerProprietario.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />
                    <br/>

                    <p:panel id="addressPanel"
                             style="background: none; border: none; margin-left: -15px; margin-top: -25px;" 
                             styleClass="container_24 clearfix both ">
                        <h4 class="title">Endereço</h4>

                        <p:outputLabel value="CEP:" styleClass="grid_3" for="cepInputMask" />
                        <p:inputMask  id="cepInputMask" styleClass="grid_4" mask="99.999-999"
                                      value="#{managerProprietario.proprietario.endereco.cep}" 
                                      required="true" requiredMessage="Cep é Obrigatório"> 
                            <p:ajax event="blur" update=":cidadaoForm:addressPanel"  
                                    listener="#{managerProprietario.existeEndereco()}" />
                        </p:inputMask>
                        <div class="clear"/>

                        <p:outputLabel value="Cod. Logra.:" styleClass="grid_3" 
                                       for="codLogradouroInputText" />
                        <p:inputText id="codLogradouroInputText" styleClass="grid_4" 
                                     value="#{managerProprietario.proprietario.endereco.codLogradouro}" />

                        <p:outputLabel value="Logradouro:" styleClass="grid_3 alpha" for="patioInputText" />
                        <p:inputText id="patioInputText" styleClass="grid_13" 
                                     value="#{managerProprietario.proprietario.endereco.logradouro}" />

                        <p:outputLabel value="Cod. Bairro:" styleClass="grid_3" for="codBairroInputText" />
                        <p:inputText id="codBairroInputText" styleClass="grid_4" 
                                     value="#{managerProprietario.proprietario.endereco.codBairro}" />

                        <p:outputLabel value="Bairro: " styleClass="grid_3 alpha" for="bairroInputText" />
                        <p:inputText id="bairroInputText" styleClass="grid_13" 
                                     value="#{managerProprietario.proprietario.endereco.bairro}" />

                        <p:outputLabel value="Estado: " styleClass="grid_3" for="estadoInputText" />
                        <p:inputText id="estadoInputText" styleClass="grid_4"
                                     value="#{managerProprietario.proprietario.endereco.uf}" />

                        <p:outputLabel value="Município: " styleClass="grid_3 alpha" for="municipioInputText" />
                        <p:inputText id="municipioInputText" styleClass="grid_13"
                                     value="#{managerProprietario.proprietario.endereco.municipio}" />

                        <p:outputLabel value="Número: " styleClass="grid_3" for="numInputText" />
                        <p:inputText id="numInputText" styleClass="grid_4"
                                     value="#{managerProprietario.proprietario.endereco.numero}" />

                        <p:outputLabel value="Complemento: " styleClass="grid_3 alpha" for="complementInputText" />
                        <p:inputText id="complementInputText" styleClass="grid_13" 
                                     value="#{managerProprietario.proprietario.endereco.compl}" />

                    </p:panel>
                </p:panel>

                <br/>
                <div class="buttonAction">
                    <p:commandButton value="Salvar" icon="ui-icon-disk"
                                     update="@form" 
                                     actionListener="#{managerProprietario.save()}"
                                     styleClass="ui-priority-primary" />

                    <p:button href="indexproprietario.xhtml" value="Cancelar"  icon="ui-icon-trash" />
                </div >
            </h:form>
        </ui:define>
    </ui:composition>

</html>
